home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Fun, Tricks & Hacks / Silent Alarm, not! / SonicAlarm.h < prev    next >
Text File  |  1992-06-15  |  10KB  |  321 lines

  1. #ifndef __SONICALARM__
  2. #define __SONICALARM__
  3. #endif
  4.  
  5.  
  6.  
  7.  
  8. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. // resources IDs 
  10.  
  11. // STR# resources
  12. #define    kErrStrings            1000    // error string list 
  13.  
  14. // error string indexes for kErrStrings
  15. enum {
  16.     eFatalErr = 1,                    // fatal error, cannot continue
  17.     eNoMemory,                        // out of memory
  18.     eNoWindow,                        // couldn't create window
  19.     eNoSndInDevice,                    // no sound input device
  20.     eSndOutMgr,                        // sound ouput error
  21.     eSndInMgr,                        // sound input error
  22.     eSettingMeter,                    // could not set level metering
  23.     eFeatureNotAvailable            // system to wimpy
  24. };
  25.  
  26. // menus 
  27. // The menu IDs  have an "m" prefix and item numbers have an "i" prefix. 
  28.  
  29. #define    rMenuBar                1000    
  30.  
  31. #define    mApple                    128
  32. enum {
  33.     iAbout = 1
  34. };
  35.  
  36. #define    mFile                    129
  37. enum {
  38.     iQuit = 1
  39. };
  40.  
  41. #define    mEdit                    130
  42. enum {
  43.     iUndo = 1,
  44.     iCut = 3,
  45.     iCopy,
  46.     iPaste,
  47.     iClear
  48. };
  49.  
  50. #define    mAlarm                    131
  51. enum {
  52.     iSetPassword = 1,
  53.     iActivate = 3
  54. };
  55.  
  56. // ALRT resources 
  57. #define    rAboutAlert                1000 
  58. #define    rUserAlert                1001
  59. #define rPasswordsDoNotMatch    1002
  60.  
  61. // WIND resource
  62. #define kAlarmWindow            1000
  63. #define kActivationWindow        1001
  64. #define kConfigurationWindow    1002
  65. #define kDeactivationWindow        1003
  66. #define kSetPasswordWindow        1004
  67.  
  68. // CNTL resources
  69. #define kCancelCountDown        1000
  70.  
  71. #define kConfigurationCancel    1001
  72. #define kConfigurationOK        1002
  73.  
  74. #define kDeactivationOK            1003
  75.  
  76. #define kSetPasswordCancel        1004
  77. #define kSetPasswordOK            1005
  78.  
  79. // RECT resources
  80. #define kActivationCountRect    1000
  81. #define kActivationMsgRect        1001
  82.  
  83. #define kConfigureLevelRect        1002
  84. #define kTestLightRect            1003
  85. #define kSensitivityRect        1004
  86. #define kConfigureMsgRect        1005
  87.  
  88. #define kPasswordRect            1006
  89. #define kDeactivationMsgRect     1007
  90. #define kDeactivationCountRect    1008
  91.  
  92. #define kSetPasswordMsgRect        1009
  93. #define kSetPasswordRect        1010
  94.  
  95. // STR resources
  96. #define kActivationMessage        1000
  97. #define kAlarmMessage            1001
  98.  
  99. #define kDeactivationMessage    1002
  100.  
  101. #define kSetPassword1Message    1003
  102. #define kSetPassword2Message    1004
  103.  
  104. #define kConfigureMessage        1005
  105. #define kSensitivityTitle        1006
  106. #define kSensitivityMax            1007
  107. #define kSensitivityMin            1008
  108.  
  109. // Strg resource (the password)
  110. #define kPasswordResID            1000
  111.  
  112. // snd resources
  113. #define kAlarmTriggeredSnd        1000
  114. #define kAlarmActivatedSnd        1001
  115. #define kAlarmDeactivatedSnd    1002
  116.  
  117.  
  118. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. // constants
  120.  
  121. // for some reason the Think C Traps.h file is not up to date with MPW 3.2
  122. // this trap should have been defined, as it appears in MPW
  123. #ifdef THINK_C
  124. #define _SoundDispatch        0xA800        /* Sound Manager dispatch trap */
  125. #endif
  126.  
  127. #define kMinHeap            (80L*1024L)    /* minimal heap size I want to run in */
  128.  
  129. #define kOSTrapBit            (1<<11)        /* bit 11 is the OS Trap bit */
  130.  
  131. #define kATrapBits            0xA800        /* bits used by the A-Trap mechanism */
  132.  
  133. #define kSystemSeven        0x00000700    /* gestaltSystemVersion result for System 7.0 */
  134.  
  135. #define kFatalError            true        /* error was fatal for AlertUser */
  136.  
  137. #define kAlarmedSleep        10            /* sleep amount while in foreground */
  138. #define kNotAlarmedSleep    MAXLONG        /* sleeping amount while in background */
  139.  
  140. #define kOneSecondTicks        60            /* 60 ticks in a second */
  141.  
  142. #define kFixed100Percent    0x00010000    /* Fixed representation of 100% */
  143.  
  144. #define kNumLevelsShift        5            /* a power of 2 to determine the number of levels */
  145. #define kNumberOfLevels        (1<<kNumLevelsShift) /* number of levels in the array */
  146.  
  147. #define kPasswordResType    'Strg'        /* the password resource type */
  148. #define kLengthOfPassword    15            /* how many chars in the password */
  149.  
  150. #define kActivationDelay    10            /* alarm activation in seconds */
  151. #define kDeactivationDelay    10            /* alarm deactivation in seconds */
  152. #define kVisualDelay        8            /* number of ticks to delay button selection */
  153.  
  154. #define kDefaultSensitivity 80            /* default percentage of sensitivity for alarm */
  155. #define kMimimumSensivity    30            /* minimum percentage of sensitivity allowed */
  156.  
  157. #define kSystemFontSize        0            /* default sytem font size */
  158. #define kActivatingFontID    applFont    /* font used to display count down */
  159. #define kActivatingFontSize    36            /* size of count down font */
  160. #define kAlarmFontID        applFont    /* font used to display main alarm message */
  161. #define kAlarmFontSize        48            /* size of main alarm message font */
  162. #define kSensitivityFontSize 9            /* size of the sensitivity control font */
  163.  
  164. #define kSpaceBelowMBar        20            /* space of alarm message below Menus */
  165. #define kEditTextInset        3            /* space inside of edit text frames */
  166. #define kSensitivitySpace    3            /* space outside of control for titles */
  167.  
  168. #define kDITopLeft            0x00500070    /* Point position of the Disk Init dialog */
  169.  
  170. #define kIsColorPort        0xC000        /* 2 high bits set in portVersion of a CGrafPort */
  171.  
  172. #define charBullet            '•'            /* used to filter password chars */
  173. enum {
  174.     kDeactivatedState = 0,                /* alarm is not active */
  175.     kActivatingState,                    /* alarm is activating itself */
  176.     kDeactivatingState,                    /* alarm is being deactivated */
  177.     kConfiguringState,                    /* alarm is bing configured, it's a test */
  178.     kActivatedState                        /* alarm is activated */
  179. };
  180.  
  181.  
  182. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183. // types
  184.  
  185. typedef struct {
  186.     WindowRecord    window;
  187.     StringHandle    message;            // message drawn while the alarm is activated
  188.     Rect            msgRect;            // where to draw the message
  189.     long            lastTickCount;        // TickCount to draw the alarmed message
  190.     short            secondsCountDown;
  191.     Boolean            drawWhite;            // alternating colors flag
  192. } AlarmWindow, *AlarmWindowPtr;
  193.  
  194. typedef struct {
  195.     WindowRecord    window;
  196.     StringHandle    message;            // message drawn while the alarm is activated
  197.     Rect            msgRect;            // where to draw the message
  198.     Point            delayPt;            // where to draw the count down numbers
  199.     long            lastTickCount;        // TickCount to draw the alarmed message
  200.     short            secondsCountDown;    // the number of seconds left in the count down
  201. } ActivationWindow, *ActivationWindowPtr;
  202.  
  203. typedef struct {
  204.     WindowRecord    window;
  205.     StringHandle    message;            // message drawn while the alarm is deactivating
  206.     Rect            msgRect;            // deactivation message area
  207.     Rect            passwordRect;        // the user's password area
  208.     Point            delayPt;            // where to draw the count down numbers
  209.     long            lastTickCount;        // TickCount to signal the alarm
  210.     short            secondsCountDown;    // the number of seconds left in the count down
  211.     unsigned char    password[kLengthOfPassword+1]; // password being entered, plus length
  212. } DeactivationWindow, *DeactivationWindowPtr;
  213.  
  214. typedef struct {
  215.     WindowRecord    window;
  216.     StringHandle    message;            // message drawn while configuring alarm
  217.     StringHandle    sensitivityTitle;    // title of the sensitivity control
  218.     StringHandle    max;                // message next to top of control
  219.     StringHandle    min;                // message next to bottom of control
  220.     Rect            levelRect;            // the volume level's area
  221.     Rect            testLightRect;        // the test light indicator area
  222.     Rect            sensitivityRect;    // the user control are
  223.     Rect            msgRect;            // message shown to user
  224.     short            sensitivity;        // user's setting of control value
  225.     long            lastTickCount;    
  226.     Boolean            testLightOn;
  227. } ConfigurationWindow, *ConfigurationWindowPtr;
  228.  
  229. typedef struct {
  230.     WindowRecord    window;
  231.     StringHandle    message;            // message drawn while the alarm is deactivating
  232.     Rect            msgRect;            // message shown to user
  233.     Rect            passwordRect;        // area for password
  234.     Boolean            firstPhase;            // entering the password for the first time
  235.     Boolean            accepted;            // true if password was accepted
  236.     unsigned char    password1[kLengthOfPassword+1]; // password being entered, plus length
  237.     unsigned char    password2[kLengthOfPassword+1]; // password being entered, plus length
  238. } SetPasswordWindow, *SetPasswordWindowPtr;
  239.  
  240.  
  241. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  242. // macros 
  243.  
  244. // Define HighWord and LowWord macros for efficiency. 
  245. #define HighWord(aLong)        (((aLong) >> 16) & 0xFFFF)
  246. #define LowWord(aLong)        ((aLong) & 0xFFFF)
  247.  
  248. // accessing a rectangle's points
  249. #define TopLeft(r)            (* (Point *) &(r).top)
  250. #define BottomRight(r)        (* (Point *) &(r).bottom)
  251.  
  252. // "easy to use" methods for testing, setting, and clearing bits
  253. #define SetBits(bits, dest)            (dest |= (bits))
  254. #define ClearBits(bits, dest)        (dest &= ~(bits))
  255. #define IsBitsAreSet(bits, dest)    (dest & (bits))
  256. #define IsBitsAreClear(bits, dest)    (!(dest & (bits)))
  257.  
  258.  
  259. #define DEBUG true
  260.  
  261. // This will insert debugging code in the application to check conditions
  262. // and displays a message in the debugger if true
  263. #ifdef DEBUG
  264. #define FailMsg(cond)                                        \
  265.     if (cond) {                                                \
  266.         DebugStr((ConstStr255Param)"\p"#cond);                \
  267.     }
  268. #else
  269. #define FailMsg(cond)                                        \
  270.     ((void)    0)
  271. #endif
  272.  
  273. // check for the exception, and if true call the action and then goto handler
  274. #ifdef DEBUG
  275. #define FailIf(cond, handler)                                \
  276.     if (cond) {                                                \
  277.         DebugStr((ConstStr255Param)"\p"#cond);                \
  278.         goto handler;                                        \
  279.     }
  280. #else
  281. #define FailIf(cond, handler)                                \
  282.     if (cond) {                                                \
  283.         goto handler;                                        \
  284.     }
  285. #endif
  286.  
  287.  
  288. // check for the exception, and if true call the action and then goto handler
  289. #ifdef DEBUG
  290. #define FailWithAction(cond, action, handler)                \
  291.     if (cond) {                                                \
  292.         DebugStr((ConstStr255Param)"\p"#cond);                \
  293.         { action; }                                            \
  294.         goto handler;                                        \
  295.     }
  296. #else
  297. #define FailWithAction(cond, action, handler)                \
  298.     if (cond) {                                                \
  299.         { action; }                                            \
  300.         goto handler;                                        \
  301.     }
  302. #endif
  303.  
  304.  
  305. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  306. // inlines
  307.  
  308. // copy a pascal string, the real way - NEVER USE _BlockMove FOR THIS !
  309.  
  310. #pragma parameter PascalStringCopy(__A0,__A1)
  311. void PascalStringCopy(const StringPtr src, StringPtr dest) =
  312. {0x7000, 0x1010, 0x12D8, 0x51C8, 0xFFFC};
  313.  
  314. //PascalStringCopy
  315. //        moveq    #0,d0            ; clear the index register
  316. //        move.b    (a0),D0            ; get string length
  317. //Loop    move.b    (a0)+,(a1)+        ; copy bytes, one greater for length byte
  318. //        dbra    d0,Loop            ;   continue until less than 0
  319.  
  320.  
  321.